<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['params']['status']=0;
	exi($return);
}
if($_RQ['op']=='list'){	
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$status=intval($_RQ['status']);
	$params['status']=$status;
	$page=intval($_RQ['page']);
	if(!$page){
		$page=1;
	}
	$limit=array($page,10);
	$list=pdo_getslice('jy_peiorder_baodan',$params,$limit,$total,'','','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['statustitle']=$this->baodanstatus[$item['status']];
			$item['paytypetitle']=$this->baopaytype[$item['paytype']];
			$item['ispaytitle']=$item['ispay']?'已支付':'未支付';
			$item['goods']=json_decode($item['goods'],true);
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_peiorder_baodan',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if(!$order['pay_id']){
			$params=array(
			'id'=>$order['id'],
			'title'=>'报单支付',
			'fee'=>$order['price'],
			//'pay_type'=>'wechat',//可选，此项作用为指定支付方式
			'no_type'=>array('hdfk'),//可选，此项作用为指定不允许使用哪种支付方式
			'back_url'=>'jy_peiorder/member.mybaodan/payresult/',//必填，指定异步支付结果通知地址，采用系统标准URL书写格式
			'success_url'=>$success_url?:'jy_peiorder/member.mybaodan/',
			'error_url'=>$error_url?:'jy_peiorder/member.mybaodan/',
		);
		if($order['merchid']){
			$merchset=plugin('jy_merch')->plugin_setting('setting');
			if($merchset['isone_credit'] && $order['merchid']){
				$params['merchid']=$order['merchid'];
			}
		}
		$payid=cfc('pay')->create_pay_order($params);
		pdo_update('jy_peiorder_baodan',array('pay_id'=>$payid),array('id'=>$order['id']));
		exi($payid);
	}
	exi($order['pay_id']);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result'];
	if($payresult['status']!=1 && $payresult['pay_type'] !='hdfk'){
		exi('支付失败。','error');
	}
	$order=pdo_get('jy_peiorder_baodan',array('id'=>$payresult['id']));
	if($order['ispay'] ==1){
		exi('该订单已经支付！','error');
	}
	if($order['price']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！'.$order['price'].'|'.$payresult['fee'],'error');
	}
	pdo_update('jy_peiorder_baodan',array('ispay'=>1,'status'=>1),array('id'=>$order['id']));
	$this->model('order')->baodan_check($order['id']);
	exi('提交成功!');
}